package main

import (
	"fmt"
	"os"
	"encoding/xml"
)

// https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/07.1.md

type Servers struct {
	XMLName xml.Name `xml:"servers"`
	Version string `xml:"version,attr"`
	Svs []server `xml:"server"`
}
type server struct{
	ServerName string `xml:"serverName"`
	ServerIP string `xml:"serverIp"`
}

func main(){
	v:=&Servers{Version:"1"}
	v.Svs=append(v.Svs,server{"shanghai_vpn","127.0.0.1"})
	v.Svs=append(v.Svs,server{"beijing_vpn","127.0.0.2"})
	output,err:=xml.MarshalIndent(v," ","   ")
	if err!=nil {
		fmt.Printf("Error: %v\n",err)
	}
	os.Stdout.Write([]byte(xml.Header))
	os.Stdout.Write(output)
}